GtkMenuTracker: tweak separator logic
authorRyan Lortie <desrt@desrt.ca>
Fri, 27 Dec 2013 03:45:03 +0000 (22:45 -0500)
committerRyan Lortie <desrt@desrt.ca>
Sat, 4 Jan 2014 07:31:08 +0000 (02:31 -0500)
Ignacio Casal Quinteiro reported a problem whereby an empty section at
the start of a menu has a separator placed after it.  This was caused by
the implementation of the logic that separators should be inserted at
the top of all non-empty sections that are not the first section.  This
logic is obviously incorrect in the case that the first section is empty
(in which case we would not expect to see a separator at the top of the
second section).

Change the logic so that we only insert separators when we see a
non-zero number of actual items in the menu before us.

https://bugzilla.gnome.org/show_bug.cgi?id=721119

gtk/gtkmenutracker.c

index 6f0f4ba8dbbfe30b6a7196094541bb217dddac6d..6027520cba881b83983a0969062083f1cddee3e3 100644 (file)
@@ -141,8 +141,8 @@ gtk_menu_tracker_section_find_model (GtkMenuTrackerSection *section,
  *
  * could_have_separator is true in two situations:
  *
- *  - our parent section had with_separators defined and we are not the
- *    first section (ie: we should add a separator if we have content in
+ *  - our parent section had with_separators defined and there are items
+ *    before us (ie: we should add a separator if we have content in
  *    order to divide us from the items above)
  *
  *  - if we had a 'label' attribute set for this section
@@ -177,7 +177,7 @@ gtk_menu_tracker_section_sync_separators (GtkMenuTrackerSection *section,
         {
           gboolean could_have_separator;
 
-          could_have_separator = (section->with_separators && i > 0) ||
+          could_have_separator = (section->with_separators && n_items > 0) ||
                                  g_menu_model_get_item_attribute (section->model, i, "label", "s", NULL);
 
           n_items += gtk_menu_tracker_section_sync_separators (subsection, tracker, offset + n_items,